﻿@{
    ViewBag.Title = "AgentSonList";
}
@{
    ViewBag.Title = "CorpManage";
}

@section scripts
{   
    <script src="@Url.Content("~/Scripts/shared/share.js")" type="text/javascript"></script> 
    <script src="@Url.Content("~/Scripts/shared/shown.js")" type="text/javascript"></script>
}
   <div class="mini-splitter" style="width:100%;height:100%;">
        <div size="400" showcollapseButton="true">
                <div class="mini-toolbar" style="padding:2px;border-top:0;border-left:0;border-right:0;"> 
                    <table style="width:100%;">
                        <tr>
                            <td style="width:100%;">
                                <a class="mini-button" id="fresh" name="fresh" iconCls="icon-search" onclick="LoadAgentList()" plain="true">刷新</a>
                                <span class="separator"></span>
                                <a class="mini-button" id="Recharge" name="Recharge" iconCls="icon-ok" onclick="setPrice" plain="true">续费设置</a>
                            </td>
                        </tr>
                    </table>
                </div>
                <div class="mini-fit" >
                    <div id="datagrid2" class="mini-datagrid" style="width:100%;height:50%;" pageSize="15"
                        borderStyle="border:1;" url="GetAgent" selectOnLoad ="true"
                        allowCellSelect="true" allowCellEdit="true"showColumnsMenu="true"fitColumns="false"  
                        sortMode="client" onselectionchanged="select">
                        <div property="columns">
                            <div type="checkcolumn" >选行</div>
                            <div type="indexcolumn" width="40" headerAlign="center" >序号</div>
                            <div field="FNumber" name="FNumber" width="80" headeralign="center" allowsort="true">编码</div>
                            <div field="FName" name="FName" width="160" headeralign="center" allowsort="true">服务商名</div>
                            <div field="InviteCode" name="InviteCode" width="80" headeralign="center" allowsort="true">邀请码</div>                            
                            <div field="FAmount" name="FAmount" width="80" headeralign="center" align="right" allowsort="true" numberFormat="#,0.00">帐户余额</div>
                            <div field="FManager" name="FManager" width="80" headeralign="center" allowsort="true">联系人</div>
                            <div field="FTelephone" name="FTelephone" width="100" headeralign="center" allowsort="true">电话</div>
                            <div field="FCreatDate" name="FCreatDate" dateFormat="yyyy-MM-dd" width="80" headeralign="center" allowsort="true">注册时间</div>
                        </div>
                    </div>
                    <div id="RGCode" style="width:100%;height:50%;padding-top:30px;">
                        <div style="width:210px;height:50px;margin:0 auto;">
                            <span style="font-size:13pt;"><strong>我的用户注册二维码</strong></span>
                        </div>
                        <div style="width:210px;height:210px;margin:0 auto;">
                            <iframe id="FM" name="FM" src=""  frameborder=0 width=210 height=210 marginheight=0 marginwidth=0 scrolling=no ></iframe>
                        </div>
                    </div>
                </div>
        </div>
        <div showCollapseButton="true">
                <div class="mini-toolbar" style="padding:2px;border-top:0;border-left:0;border-right:0;"> 
                    <table style="width:100%;">
                        <tr>
                            <td style="width:100%;">
                                <a class="mini-button" id="fresh" name="fresh" iconCls="icon-search" onclick="search()" plain="true">刷新</a>
                                <span class="separator"></span>
                                <a class="mini-button" id="paypara" name="paypara" iconCls="icon-tip" onclick="setParam" plain="true">支付参数</a>                                
                                <span class="separator"></span>
                                <a class="mini-button" id="Expiry" name="Expiry" iconCls="icon-goto" onclick="setExpiry" plain="true">系统激活</a>
                                @*<a class="mini-button" id="ClearPos" name="Agent" iconCls="icon-tip" onclick="setClearPOS" plain="true">注销前台</a>*@
                                <span class="separator"></span>
                                <a class="mini-button" id="close" name="close" iconCls="icon-close" onclick="CloseWindow" plain="true">关闭</a>
                            </td>
                        </tr>
                    </table>       
                </div>
                    <table style="margin-bottom:4px;">
                        <tr>
                            <td width ="100px" align="right">编码或名称: </td>
                            <td width ="150px" ><input class="mini-textbox" width ="150px" id ="FSearchKey1" name = "FSearchKey1" onkeypress="setkeyPress()"/></td>
                            <td width="80px" align="right">到期日期:</td>
                            <td width="310px" >
                                @Html.Partial("~/Views/Modular/dxDateRange.cshtml") 
                            </td>
                            <td width ="100px" >
                                <div id="FAtDate" name="FAtDate"  class="mini-checkbox" style ="margin-right:20px" readOnly="false" value ="false" text="按到期日期过滤">
                            </td>
                        </tr>
                    </table>                
                <div class="mini-fit" >
                    <div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;" pageSize="15"
                        borderStyle="border:1;" url="GetAgentSonList"
                        allowCellSelect="true" allowCellEdit="true"showColumnsMenu="true"fitColumns="false"  
                        sortMode="client">
                        <div property="columns">
                            <div type="checkcolumn" >选行</div>
                            <div type="indexcolumn" width="40" headerAlign="center" >序号</div>
                            <div field="FRegUserNumber" name="FRegUserNumber" width="120" headeralign="center" allowsort="true">注册用户</div>
                            <div field="FNumber" name="FNumber" width="120" headeralign="center" allowsort="true">商户编码</div>
                            <div field="FName" name="FName" width="120" headeralign="center" allowsort="true">商户名称</div>                                                                              
                            <div field="FAcCode" name="FAcCode" width="80" headeralign="center" allowsort="true">首年激活码</div>
                            <div field="FInitialPsd" name="FInitialPsd" width="80" headeralign="center" allowsort="true">初始密码</div>
                            <div field="FAddress" name="FAddress" width="100" headeralign="center" allowsort="true">地址</div>
                            <div field="FManager" name="FManager" width="80" headeralign="center" allowsort="true">联系人</div>
                            <div field="FTelephone" name="FTelephone" width="100" headeralign="center" allowsort="true">电话</div>
                            <div field="FParentNumber" name="FParentNumber" width="80" headeralign="center" allowsort="true">上级商户编码</div>
                            <div field="FParentName" name="FParentName" width="120" headeralign="center" allowsort="true">上级商户名称</div> 
                            <div field="FEMail" name="FEMail" width="100" headeralign="center" allowsort="true">EMail</div>
                            <div field="FCreatDate" name="FCreatDate" dateFormat="yyyy-MM-dd" width="80" headeralign="center" allowsort="true">注册时间</div>
                            <div field="FEndTime" dateFormat="yyyy-MM-dd hh:mm:ss" name="FEndTime" width="130" headeralign="center" allowsort="true">到期时间</div>                        
                            <div field="FCustName" name="FCustName" width="150" headeralign="center" allowsort="true">客户名称</div>
                            <div field="FClassName" name="FClassName" width="180" headeralign="center" allowsort="true">服务商</div>                            
                            <div field="FRemark" name="FRemark" width="100" headeralign="center" allowsort="true">备注</div>
                        </div>
                    </div>
                </div>
        </div>
   </div>
<script>
    function FormShown() {
        mini.parse();
        var toDay = new Date();
        mini.getbyName("FDate1").setValue(toDay);
        mini.getbyName("FDate2").setValue(toDay);
        LoadAgentList();
        //mini.getbyName("delrow").disable();
        $("#FM").attr("src", "../System/GetRegistCode?mSystemAppID=" + encodeURIComponent(parent.window.getSystemAppID()));
    }

    //加载资料列表
    function LoadListData() {
        var mDateType = "0";
        if (mini.getbyName("FAtDate").checked == true) mDateType = "1";
        var cDate1 = mini.getbyName("FDate1").getFormValue();
        var cDate2 = mini.getbyName("FDate2").getFormValue();
        var json = "[{";
        json = json + "'search':" + "'" + mini.getbyName("FSearchKey1").getValue() + "',";
        json = json + '"mDate1":' + '"' + cDate1 + '",';
        json = json + '"mDate2":' + '"' + cDate2 + '",';
        json = json + '"mAtDate":' + '"' + mDateType + '",';
        json = json + "'mSystemAppID':" + "'" + parent.window.getSystemAppID() + "'";
        json = json + "}]";
        var grid = mini.get("datagrid1");
        grid.load({ mjson: json });
    }

    function setParam() {
        var grid = mini.get("datagrid1");
        var row = grid.getSelected();
        if (row) {
            mini.open({
                url: "/Corp/PayParam",
                title: "支付参数设置", width: 600, height: 400,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var data = {
                        FItemID: row.FItemID, FNumber: row.FNumber, FName: row.FName
                    };
                    iframe.contentWindow.SetInfoData(data);
                },
                ondestroy: function (action) {
                    grid.reload();
                }
            });

        } else {
            mini.alert("请选中一条记录");
        }
    }

    //设置有效期
    function setExpiry() {
        var grid2 = mini.get("datagrid2");
        var row2 = grid2.getSelected();
        if (row2) {
            var grid = mini.get("datagrid1");
            var row = grid.getSelected();
            if (row) {
                mini.open({
                    url: "/Corp/ExpiryDate",
                    title: "系统激活", width: 730, height: 500,
                    onload: function () {
                        var iframe = this.getIFrameEl();
                        var data = {
                            FItemID: row.FItemID, FNumber: row.FNumber, FName: row.FName, FClassID: row2.FCorpID
                        };
                        iframe.contentWindow.SetInfoData(data);
                    },
                    ondestroy: function (action) {
                        grid.reload();
                        //mini.get("datagrid2").reload();
                    }
                });

            } else {
                mini.alert("请选中一条记录");
            }
        }
        else {
            mini.alert("请在左边表中选一个服务商");
        }
    }

    function search() {
        LoadListData();
    }

    //加载资料列表
    function LoadAgentList() {
        var json = "[{";
        json = json + "'mSystemAppID':'" + parent.window.getSystemAppID() + "'";
        json = json + "}]";
        var grid = mini.get("datagrid2");
        grid.load({ mjson: json });
    }

    function newBill() {
        var grid = mini.get("datagrid1");
        var row = grid.getSelected();
        mini.open({
            url: "/Corp/CopySon",
            title: "商户资料", width: 350, height: 180,
            onload: function () {
                var iframe = this.getIFrameEl();
                var data = { FItemID: 1 };
                if (row)
                    data = { FItemID: row.FItemID, FNumber: row.FNumber, FName: row.FName };
                iframe.contentWindow.SetInfoData(data);
            },
            ondestroy: function (action) {
                LoadListData();
            }
        });
    }

    //修改资料
    function modify() {
        var grid = mini.get("datagrid1");
        var row = grid.getSelected();
        if (row) {
            mini.open({
                url: "/Corp/CorpInfo",
                title: "商户资料", width: 670, height: 460,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var data = {
                        FItemID: row.FItemID, FNumber: row.FNumber, FName: row.FName, FManager: row.FManager,
                        FTelephone: row.FTelephone, FAddress: row.FAddress, FEMail: row.FEMail, FBillPrtName: row.FBillPrtName,
                        FCustName: row.FCustName, FRemark: row.FRemark
                    };
                    iframe.contentWindow.SetInfoData(data);
                },
                ondestroy: function (action) {
                    grid.reload();
                }
            });

        } else {
            mini.alert("请选中一条记录");
        }
    }

    ////修改代理
    //function modifyAgent() {
    //    var grid = mini.get("datagrid2");
    //    var row = grid.getSelected();
    //    if (row) {
    //        mini.open({
    //            url: "/Corp/AgentInfo",
    //            title: "服务商资料", width: 650, height: 320,
    //            onload: function () {
    //                var iframe = this.getIFrameEl();
    //                var data = {
    //                    FItemID: row.FItemID, FNumber: row.FNumber, FName: row.FName, FManager: row.FManager, FTelephone: row.FTelephone,
    //                    FAddress: row.FAddress, FEmail: row.FEmail
    //                };
    //                iframe.contentWindow.SetInfoData(data);
    //            },
    //            ondestroy: function (action) {
    //                LoadAgentList();
    //            }
    //        });

    //    } else {
    //        mini.alert("请选中一条记录");
    //    }
    //}

    //代理充值
    function Recharge() {
        var grid = mini.get("datagrid2");
        var row = grid.getSelected();
        if (row) {
            mini.open({
                url: "/Corp/Recharge?type=9",
                title: "服务商充值", width: 650, height: 320,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var data = {
                        FItemID: row.FItemID, FNumber: row.FNumber, FName: row.FName, FManager: row.FManager, FTelephone: row.FTelephone,
                        FAddress: row.FAddress, FEmail: row.FEmail
                    };
                    iframe.contentWindow.SetInfoData(data);
                },
                ondestroy: function (action) {
                    LoadAgentList();
                }
            });

        } else {
            mini.alert("请选中一条记录");
        }
    }

    //设置代理
    function setAgent() {
        mini.confirm("确定要设置所选商家为服务商？", "提示",
            function (action) {
                if (action == "ok") {
                    var grid = mini.get("datagrid1");
                    var row = grid.getSelected();
                    if (row) {
                        $.post("setAgent", { json: row.FItemID }, function (data) {
                            var ret = mini.decode(data);
                            if (ret.status == 1) {
                                mini.showTips({ content: ret.msg, state: "success", x: "center", y: "top", timeout: 3000 });
                                LoadAgentList();
                            }
                            else {
                                mini.alert(ret.error);
                            }
                        });
                    }
                    else {
                        mini.alert("请选中一条记录");
                    }
                }
            });
    }

    //取消代理
    function CancelAgent() {
        mini.confirm("确定要取消所选服务商？", "提示",
            function (action) {
                if (action == "ok") {
                    var grid = mini.get("datagrid2");
                    var row = grid.getSelected();
                    if (row) {
                        $.post("CancelAgent", { json: row.FItemID }, function (data) {
                            var ret = mini.decode(data);
                            if (ret.status == 1) {
                                mini.showTips({ content: ret.msg, state: "success", x: "center", y: "top", timeout: 3000 });
                                LoadAgentList();
                            }
                            else {
                                mini.alert("出现错误，错误信息:" + ret.error);
                            }
                        });
                    }
                    else {
                        mini.alert("请选中一条记录");
                    }
                }
            });
    }

    //function setParam() {
    //    var grid = mini.get("datagrid1");
    //    var row = grid.getSelected();
    //    if (row) {
    //        mini.open({
    //            url: "/Corp/PayParam",
    //            title: "电商支付参数", width: 550, height: 260,
    //            onload: function () {
    //                var iframe = this.getIFrameEl();
    //                var data = {
    //                    FItemID: row.FItemID, FNumber: row.FNumber, FName: row.FName
    //                };
    //                iframe.contentWindow.SetInfoData(data);
    //            },
    //            ondestroy: function (action) {
    //                LoadListData();
    //            }
    //        });

    //    } else {
    //        mini.alert("请选中一条记录");
    //    }
    //}

    function select() {
        var grid = mini.get("datagrid2");
        var row = grid.getSelected();
        var mClassID = 0;
        if (row) mClassID = row.FItemID;
        LoadListData(mClassID);
    }

    function setPrice() {
            mini.open({
                url: "/Corp/AgentPriceSet",
                title: "价格设置", width: 700, height: 460,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var data = {};
                    iframe.contentWindow.SetInfoData(data);
                },
                ondestroy: function (action) {
                    LoadListData();
                }
            });
    }

    //注销前台
    function setClearPOS() {
        mini.confirm("确定要注销该商户的前台登陆信息吗？", "提示",
            function (action) {
                if (action == "ok") {
                    var grid = mini.get("datagrid1");
                    var row = grid.getSelected();
                    if (row) {
                        $.post("setClearPOS", { json: row.FItemID }, function (data) {
                            var ret = mini.decode(data);
                            if (ret.status == 1) {
                                mini.showTips({ content: ret.msg, state: "success", x: "center", y: "top", timeout: 3000 });
                            }
                            else {
                                mini.alert(ret.error);
                            }
                        });
                    }
                    else {
                        mini.alert("请选中一条记录");
                    }
                }
            });
    }

</script>